# code to run pivot scaling for each subset
library(data.table)
library(tidyverse)
library(parrot)

source("pundits_functions.R")

set.seed(1111)

## These won't run, as the underlying text data cannot be shared.
## The data/keyword_subset_ids folder contains a .txt file with 
## the tweet IDs included in each of these subsets

# run parrot routine on a variety of topics
china_subset <- readr::read_csv("../dictionary_subsets/full_sets/china.csv")
china_parrot <- parrot_routine_tokensub(dat = china_subset, subjname = "china")
save(china_parrot, file = "../output/parrots/china_parrot.RData")
rm(china_parrot, china_subset)

class_subset <- readr::read_csv("../dictionary_subsets/full_sets/class.csv")
class_parrot <- parrot_routine_tokensub(dat = class_subset, subjname = "class")
save(class_parrot, file = "../output/parrots/class_parrot.RData")
rm(class_parrot, class_subset)

climate_subset <- readr::read_csv("../dictionary_subsets/full_sets/climate.csv")
climate_parrot <- parrot_routine_tokensub(dat = climate_subset, subjname = "climate")
save(climate_parrot, file = "../output/parrots/climate_parrot.RData")
rm(climate_parrot, climate_subset)

conservative_subset <- readr::read_csv("../dictionary_subsets/full_sets/conservative.csv")
conservative_parrot <- parrot_routine_tokensub(dat = conservative_subset, subjname = "conservative")
save(conservative_parrot, file = "../output/parrots/conservative_parrot.RData")
rm(conservative_parrot, conservative_subset)

far_left_subset <- readr::read_csv("../dictionary_subsets/full_sets/far_left.csv")
far_left_parrot <- parrot_routine_tokensub(dat = far_left_subset, subjname = "far_left")
save(far_left_parrot, file = "../output/parrots/far_left_parrot.RData")
rm(far_left_parrot, far_left_subset)

far_right_subset <- readr::read_csv("../dictionary_subsets/full_sets/far_right.csv")
far_right_parrot <- parrot_routine_tokensub(dat = far_right_subset, subjname = "far_right")
save(far_right_parrot, file = "../output/parrots/far_right_parrot.RData")
rm(far_right_parrot, far_right_subset)

gender_subset <- readr::read_csv("../dictionary_subsets/full_sets/gender.csv")
gender_parrot <- parrot_routine_tokensub(dat = gender_subset, subjname = "gender")
save(gender_parrot, file = "../output/parrots/gender_parrot.RData")
rm(gender_parrot, gender_subset)

guns_subset <- readr::read_csv("../dictionary_subsets/full_sets/guns.csv")
guns_parrot <- parrot_routine_tokensub(dat = guns_subset, subjname = "guns")
save(guns_parrot, file = "../output/parrots/guns_parrot.RData")
rm(guns_parrot, guns_subset)

health_care_insurance_subset <- readr::read_csv("../dictionary_subsets/full_sets/health_care_insurance.csv")
health_care_insurance_parrot <- parrot_routine_tokensub(dat = health_care_insurance_subset, subjname = "health_care_insurance")
save(health_care_insurance_parrot, file = "../output/parrots/health_care_insurance_parrot.RData")
rm(health_care_insurance_parrot, health_care_insurance_subset)

immigration_subset <- readr::read_csv("../dictionary_subsets/full_sets/immigration.csv")
immigration_parrot <- parrot_routine_tokensub(dat = immigration_subset, subjname = "immigration")
save(immigration_parrot, file = "../output/parrots/immigration_parrot.RData")
rm(immigration_parrot, immigration_subset)

iran_subset <- readr::read_csv("../dictionary_subsets/full_sets/iran.csv")
iran_parrot <- parrot_routine_tokensub(dat = iran_subset, subjname = "iran")
save(iran_parrot, file = "../output/parrots/iran_parrot.RData")
rm(iran_parrot, iran_subset)

israel_subset <- readr::read_csv("../dictionary_subsets/full_sets/israel.csv")
israel_parrot <- parrot_routine_tokensub(dat = israel_subset, subjname = "israel")
save(israel_parrot, file = "../output/parrots/israel_parrot.RData")
rm(israel_parrot, israel_subset)

lgbt_subset <- readr::read_csv("../dictionary_subsets/full_sets/lgbt.csv")
lgbt_parrot <- parrot_routine_tokensub(dat = lgbt_subset, subjname = "lgbt")
save(lgbt_parrot, file = "../output/parrots/lgbt_parrot.RData")
rm(lgbt_parrot, lgbt_subset)

liberal_subset <- readr::read_csv("../dictionary_subsets/full_sets/liberal.csv")
liberal_parrot <- parrot_routine_tokensub(dat = liberal_subset, subjname = "liberal")
save(liberal_parrot, file = "../output/parrots/liberal_parrot.RData")
rm(liberal_parrot, liberal_subset)

mueller_subset <- readr::read_csv("../dictionary_subsets/full_sets/mueller.csv")
mueller_parrot <- parrot_routine_tokensub(dat = mueller_subset, subjname = "mueller")
save(mueller_parrot, file = "../output/parrots/mueller_parrot.RData")
rm(mueller_parrot, mueller_subset)

progressive_subset <- readr::read_csv("../dictionary_subsets/full_sets/progressive.csv")
progressive_parrot <- parrot_routine_tokensub(dat = progressive_subset, subjname = "progressive")
save(progressive_parrot, file = "../output/parrots/progressive_parrot.RData")
rm(progressive_parrot, progressive_subset)

race_subset <- readr::read_csv("../dictionary_subsets/full_sets/race.csv")
race_parrot <- parrot_routine_tokensub(dat = race_subset, subjname = "race")
save(race_parrot, file = "../output/parrots/race_parrot.RData")
rm(race_parrot, race_subset)

reproductive_health_subset <- readr::read_csv("../dictionary_subsets/full_sets/reproductive_health.csv")
reproductive_health_parrot <- parrot_routine_tokensub(dat = reproductive_health_subset, subjname = "reproductive_health")
save(reproductive_health_parrot, file = "../output/parrots/reproductive_health_parrot.RData")
rm(reproductive_health_parrot, reproductive_health_subset)

taxes_spending_subset <- readr::read_csv("../dictionary_subsets/full_sets/taxes_spending.csv")
taxes_spending_parrot <- parrot_routine_tokensub(dat = taxes_spending_subset, subjname = "taxes_spending")
save(taxes_spending_parrot, file = "../output/parrots/taxes_spending_parrot.RData")
rm(taxes_spending_parrot, taxes_spending_subset)

trade_subset <- readr::read_csv("../dictionary_subsets/full_sets/trade.csv")
trade_parrot <- parrot_routine_tokensub(dat = trade_subset, subjname = "trade")
save(trade_parrot, file = "../output/parrots/trade_parrot.RData")
rm(trade_parrot, trade_subset)

democrat_subset <- readr::read_csv("../dictionary_subsets/full_sets/democrat.csv")
democrat_parrot <- parrot_routine_tokensub(dat = democrat_subset, subjname = "democrat")
save(democrat_parrot, file = "../output/parrots/democrat_parrot.RData")
rm(democrat_parrot, democrat_subset)

republican_subset <- readr::read_csv("../dictionary_subsets/full_sets/republican.csv")
republican_parrot <- parrot_routine_tokensub(dat = republican_subset, subjname = "republican")
save(republican_parrot, file = "../output/parrots/republican_parrot.RData")
rm(republican_parrot, republican_subset)